// SendLog.cpp: implementation of the CSendLog class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "NetTV.h"
#include "SendLog.h"
#include "Globals.h"
#include <stdio.h>
#include <time.h>
extern string LOCAL_IPADDR;

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSendLog::CSendLog()
{
	fd = socket.CreateSocket(0);
}

CSendLog::~CSendLog()
{
	free(addr);
}

BOOL CSendLog::SendAgentAction(LOGLEVEL level, string msg)
{
	char tmp[256];
	char buffer[256];
	time_t  timeval;

	CListBox* listbox4 = (CListBox*)(AfxGetApp()->GetMainWnd()->GetDlgItem(IDC_LIST4));
	timeval = time(0);
	strftime(tmp,100,"%Y/%m/%d %H:%M:%S",localtime((time_t *)&(timeval)));
	sprintf(buffer,"%s %s",tmp,msg.c_str());
	listbox4->InsertString(listbox4->GetCount(),buffer);
	
	memset(tmp,256,0);
	sprintf(tmp,"<%s> <2> %s",LOCAL_IPADDR.c_str(),msg.c_str());
	struct sockaddr_in addr;
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = inet_addr(LOGSERVER_IPADDR.c_str());
	addr.sin_port = htons(LOGSERVER_PORT);
	sendto(fd,tmp,sizeof(tmp),0,(struct sockaddr*)&addr,sizeof(struct sockaddr));
	return TRUE	;
}
